package com.polaris.live.popup

import android.content.Context
import android.text.TextUtils
import android.view.ViewGroup
import com.blankj.utilcode.util.StringUtils
import com.blankj.utilcode.util.TimeUtils
import com.lxj.xpopup.core.BottomPopupView
import com.polaris.live.R
import com.polaris.live.adapter.backpack.BackPackBubbleAdapter
import com.polaris.live.common.ext.convertArabicDigitsToNormal
import com.polaris.live.common.ext.dp
import com.polaris.live.common.util.AppCodeUtils
import com.polaris.live.common.util.NavigationBarUtils
import com.polaris.live.databinding.PopupBackpackDetailsBinding
import com.polaris.live.resp.back_resp.UserBackpackDecorationResp
import com.polaris.live.translation.R.string

/**
 * BackPackDetailsPopup
 *
 * @author Created by 半仙 on 2024/1/31/031 11:48
 */
class BackPackDetailsPopup(
    context: Context,
    private val mUserBack: UserBackpackDecorationResp,
) : BottomPopupView(context) {
    private lateinit var mBinding: PopupBackpackDetailsBinding

    override fun getImplLayoutId() = R.layout.popup_backpack_details

    override fun onCreate() {
        super.onCreate()
        mBinding = PopupBackpackDetailsBinding.bind(popupImplView)
        setData(mUserBack)
        NavigationBarUtils.setNavigationHeightIfTransparent(mBinding.placeHolding) { view, height ->
            val layoutParams = view.layoutParams as ViewGroup.LayoutParams
            layoutParams.height = height + 10.dp
            mBinding.placeHolding.layoutParams = layoutParams
        }
    }

    fun setData(mUserBack: UserBackpackDecorationResp) {
        if (!TextUtils.isEmpty(mUserBack.description)) {
            mBinding.tvContext.text = mUserBack.description
        }
        if (mUserBack.backpackId == BackPackBubbleAdapter.NOT_HAVE) {
            mBinding.tvTime.text = StringUtils.getString(string.not_get_it)
        } else {
            mUserBack.createTime?.toLong()?.let {
                val millis2String =
                    TimeUtils.millis2String(it, "yyyy-MM-dd").convertArabicDigitsToNormal()
                val showTime = if (AppCodeUtils.isAR()) {
                    "$millis2String${StringUtils.getString(string.get_it)}"
                } else {
                    "$millis2String${StringUtils.getString(string.get_it)}"
                }
                mBinding.tvTime.text = showTime
            }
        }
    }
}